<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>快速排序</title>
</head>
<body>
    

    <script>
    
        {
            // 快速排序

            let ary = [10,8,12,14,13,11,9,15];

           function rapidSort (ary) {
                if(ary.length<=1){
                    return ary;
                }
                let index = Math.floor(ary.length/2);
                let centerVal = ary.splice(index,1)[0];
                let left = [],right = [];
                for(let i=0;i<ary.length;i++){
                    let ele = ary[i];
                    ele<centerVal?left.push(ele):right.push(ele);
                }
                return rapidSort(left).concat(centerVal,rapidSort(right));
           }

            console.log(rapidSort(ary));
            

        }
        
    </script>

</body>
</html>